package net.xdclass.component.impl;

import lombok.extern.slf4j.Slf4j;
import net.xdclass.component.MailServie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @Description:
 * @Author:xuezhen
 * @CreateDate:2021/4/7 21:12
 * @UpdateUser:
 * @UpdateDate:
 * @UpdateRemark:
 * @Version:v2.0
 */
@Slf4j
@Service
public class MailserviceImpl implements MailServie {

    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String username;

    @Override
    public void sendMail(String to, String subject, String content) {
        // 创建一个邮箱消息对象
        SimpleMailMessage message = new SimpleMailMessage();
        // 邮件发送人
        message.setFrom(username);
        // 收件人
        message.setTo(to);
        // 邮件主题
        message.setSubject(subject);
        // 邮件的内容
        message.setText(content);
        javaMailSender.send(message);
        log.info("邮件发送成功:{}",message);
    }
}
